<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <template v-if="isDeleteShow">
        <span @click="searchHistories.splice(0,searchHistories.length)">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isDeleteShow=false">完成</span>
      </template>
      <van-icon @click="isDeleteShow=true" v-else name="delete" />
    </van-cell>
    <van-cell @click="del(index)" :title="item" v-for="(item,index) in searchHistories" :key="index">
      <van-icon v-show="isDeleteShow" name="delete" />
    </van-cell>
  </div>
</template>

<script>
// 单向数据流：父组件值的更新,会影响到子组件,反之则不行 如果强行去改可以生效但是控制台会报错
// 特殊情况：如果父向传的是数组或对象类型是可以改，但是只能添加属性，不能直接改地址
export default {
  name: 'SearchHistory',
  components: {},
  props: {
    searchHistories: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      isDeleteShow: false
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    del (index) {
      this.searchHistories.splice(index, 1)
    }
  }
}
</script>

<style scoped lang="less"></style>
